//
//  SDCommentCell.m
//  Sydeny
//
//  Created by Rainbow on 8/13/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SDCommentCell.h"
#import "UtilHelper.h"


@implementation SDCommentCell
@synthesize comment;


-(id)initWithComment:(Comment *)aComment reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.comment = aComment;
        nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 280, 20)];
        nameLbl.textAlignment = UITextAlignmentLeft;
        nameLbl.text = self.comment.username;
        nameLbl.font = [UIFont systemFontOfSize:14];
        nameLbl.textColor = [UIColor brownColor];
        [self addSubview:nameLbl];
        
        NSInteger contentHeight = [self.comment.content sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(280, 200) lineBreakMode:UILineBreakModeWordWrap].height;
        contentLbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 25, 280, contentHeight)];
        contentLbl.numberOfLines = 0;
        contentLbl.text = self.comment.content;
        contentLbl.lineBreakMode = UILineBreakModeWordWrap;
        contentLbl.font = [UIFont systemFontOfSize:14];
        [self addSubview:contentLbl];
        
        
        timeLbl = [[UILabel alloc] initWithFrame:CGRectMake(10, contentHeight + 30, 280, 20)];
        timeLbl.textAlignment = UITextAlignmentLeft;
        timeLbl.text = [UtilHelper getDateByInterval:[self.comment.timestamp floatValue]];
        timeLbl.font = [UIFont systemFontOfSize:12];
        timeLbl.textColor = [UIColor grayColor];
        [self addSubview:timeLbl];
        
        
    }
    return self;
}


-(void)updateWithComment:(Comment *)aComment
{
    self.comment = aComment;
    nameLbl.text = self.comment.username;
    timeLbl.text = [UtilHelper getDateByInterval:[self.comment.timestamp floatValue]];
    NSInteger contentHeight = [self.comment.content sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(280, 200) lineBreakMode:UILineBreakModeWordWrap].height;
    contentLbl.text = self.comment.content;
    contentLbl.frame = CGRectMake(10, 25, 280, contentHeight);
    timeLbl.frame = CGRectMake(10, contentHeight + 30, 280, 20);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc
{
    self.comment = nil;
    [nameLbl release];
    nameLbl = nil;
    [contentLbl release];
    contentLbl = nil;
    [timeLbl release];
    timeLbl = nil;
    [super dealloc];
}

@end
